package gui;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import environment.Casilla;

public class CasillasGUI extends javax.swing.JPanel implements CasillaListener {
	private Casilla cas;
	private TableroGUI tablero;
	private ImageIcon fondo;
	private static int [] casillaMarcada = new int[2];
	
	public CasillasGUI() {
		// este constructor no se usar&aacute;, se deja para poder crear el bean.
	}
	
	public CasillasGUI(TableroGUI t, Casilla c) {
		initComponents();
		this.cas = c;
		this.cas.setGuiElement(this);
		this.tablero = t;
	}
	
	public void setFondo(ImageIcon fondo){
		this.fondo = fondo;
	}
	
	public ImageIcon getFondo(){
		return this.fondo;
	}
	
	private void initComponents() {
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 161, Short.MAX_VALUE));
		layout.setVerticalGroup(
		layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 193, Short.MAX_VALUE));
	}
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.drawImage(fondo.getImage(), 0, 0, this.getWidth(), this.getHeight(), this);
		g.drawString(Integer.toString(cas.getGradiente()), 0, 10);
	}

	public static int[] getCasillaMarcada() {
		return casillaMarcada;
	}
		
	public static void setCasillaMarcada(int[] aCasillaMarcada) {
		casillaMarcada = aCasillaMarcada;
	}

	public void casillaUpdate(CasillaEvent e) {
		this.setCasillaMarcada(tablero.getCoordenadas((Casilla) e.getSource()));
		this.tablero.pintar(this.getCasillaMarcada()[0],this.getCasillaMarcada()[1], e.what);
	}
}